package display;


import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;

import universe.BlockHandler;
import universe.Game;

@SuppressWarnings("serial")
public class BlockDisplay extends JPanel{

		Game theGame;
		BlockHandler theBlockHandler;
	
		public BlockDisplay(Game pGame){
			super();
			theGame = pGame;
			theBlockHandler = theGame.getCurrentBlock();
			this.setSize(display.Utils.getBoardWidthPx(), display.Utils.getBoardHeightPx());
			
			// Fond transparent
			this.setOpaque(false);
			
			
			//System.out.println("allo les gens :" + display.Utils.getBlockWidthPx() +" " + display.Utils.getBlockHeightPx());
		}
		
		public void paintComponent(Graphics g){
			theBlockHandler = theGame.getCurrentBlock();
			for(int i=0; i<universe.Utils.BLOCK_WIDTH;i++){
				for(int j=0; j<universe.Utils.BLOCK_HEIGHT;j++){
					if(theBlockHandler.getB().getCell(i, j) != 0){
						g.setColor(Utils.getColor(theBlockHandler.getB().getCell(i, j)));
						g.fillRect((theBlockHandler.getX()+i)*Utils.sideWidth, (theBlockHandler.getY()+j)*Utils.sideWidth, Utils.sideWidth, Utils.sideWidth);
					}	
				}
			}
		}


		public BlockHandler getBlockHandler() {
			return theBlockHandler;
		}


		public void setBlockHandler(BlockHandler pBlockHandler) {
			this.theBlockHandler = pBlockHandler;
		}
	
}
